import { onMounted, watch, ref } from 'vue';
import bus from '@/layout/components/bus';
import modal from '@/plugins/modal';

// 监听table页面 多选行操作 控制批量操作按钮的显隐
// 监听批量操作的按钮点击事件  回调页面的批量操作事件
// 参数1 ids 选中的数据列表； 参数2 handleDelete页面的删除事件
export function batchingInit(tableHeight: any) {
  let isTableBig = false;
  const tableResize = () => {
    let searchDom: any = document.getElementsByClassName('yy-search-form');
    if (!searchDom || searchDom.length < 1) {
      return;
    }
    let searchHeight = searchDom[0].offsetHeight;
    let topH = 88,
      tableHH = 54,
      pageH = 24,
      allPadding = 110,
      footerH = 60;
    if (!isTableBig) {
      tableHeight.value = document.body.offsetHeight - topH - tableHH - pageH - allPadding - footerH - searchHeight;
    } else {
      tableHeight.value = document.body.offsetHeight - tableHH - pageH - 70;
    }
  };

  onMounted(() => {
    tableResize();
    window.addEventListener('resize', tableResize);
    // 监听搜索条件 显示更多变化
    bus.on('showSearchConfig', (data: any) => {
      setTimeout(() => {
        tableResize();
      }, 500);
    });
    // 监听table表格 全屏事件
    bus.on('tableSizeChange', (data: any) => {
      isTableBig = data.val;
      setTimeout(() => {
        tableResize();
      }, 500);
    });
  });
  onUnmounted(() => {
    bus.off('showSearchConfig');
    bus.off('tableSizeChange');
  });
}
